package com.finchina.myview.shader;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

/**
 * 作者：黄赛赛 on 2015/9/18 14:28
 *
 * @version V1.0
 * @Description: ${todo}()
 */
public class LinearGradientShaderView extends View{
    Paint mPaint;
    public LinearGradientShaderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);

    }

    public LinearGradientShaderView(Context context) {
        this(context, null);

    }



    public LinearGradientShaderView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    @Override
    protected void onDraw(Canvas canvas) {
//        super.onDraw(canvas);
//        mPaint.setShader(new LinearGradient(0,0, getWidth(), getHeight(), Color.GREEN, Color.RED, Shader.TileMode.CLAMP));
        mPaint.setShader(new LinearGradient(0,0, getWidth(), getHeight(), new int[] { Color.RED, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE }, new float[] { 0, 0.1F, 0.5F, 0.7F, 0.8F }, Shader.TileMode.MIRROR));

        canvas.drawRect(0,0,getWidth(),getHeight(),mPaint);

    }
}
